<?php

session_start();
error_reporting(0);
require_once('../../class_ajax_request/classAjax.php');
include_once('../../application/functions.php');
include_once('../../application/DataConfig.php');
include_once('answer.content.function.php');

if ( isset ( $_POST['user_id'] ) && isset($_POST['meta_id'])  ) {

        //echo $_POST['user_id'].'-----'.$_SESSION['authenticated'];die;

    $obj      = new AjaxRequest();
    $rs = $obj->insertanswer($_POST);



    $array = $rs['list'];
    $id = $rs['post_id'];

     $checkArray = $obj->checkAnswered( $_POST['meta_id'],$_SESSION['authenticated'] );

    $post_answer_id = $checkArray[0]['postanswerid'];
//    $post_answer_id = $rs['list'][0]['post_answer_id'];
    $post_meta_array = $obj->get_post_meta($id);
    $extra_value = $post_meta_array[0]['extra_value'];




    if($rs['data_type'] == 1){
        $array = get_default_answer($obj, $id);
        $html = binarychart($array,$id);
        echo $html;
    }
    if($rs['data_type'] == 2){
        $array = get_default_answer($obj, $id);
        $post_question =json_decode($post_meta_array[0]['meta_value']);
        $html = $obj->renderBarChart($id,$post_question,$array);
        //$html = multichart($array,json_decode($post_meta_array[0]['meta_value']));
        echo $html;
    }
    if($rs['data_type'] == 3){
        $array = get_default_answer($obj, $id);
        $post_question = json_decode($post_meta_array[0]['meta_value']);
      $html = get_slider_answer($obj,$id,'Average',$extra_value,$post_question);
        echo $html;
    }
    if($rs['data_type'] == 4){

        $array = get_default_answer($obj, $id);
        $post_question =json_decode($post_meta_array[0]['meta_value']);

        $html = get_star_answer($obj,$id,'Rating');
        echo $html;
        $html_chart = $obj->renderBarChart($id,$post_question,$array);
        echo $html_chart;
    }


//    echo '<input type="text" data-post-type="'.$rs['data_type'].'"value="'.$post_answer_id.'" >';
    echo '<div class="answer-info" data-post-type ="'.$rs['data_type'].'" data-answer-id="'.$post_answer_id.'" ></div>';
    die;
}
?>